<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" type="image/ico" href="">
	<title>vbox007's barcode page</title>
	<script src="https://cdn.bootcss.com/jsbarcode/3.8.0/JsBarcode.all.min.js">

	</script>
	<style>
		div {
			width: 256px;
			margin: 0 auto;
			text-align: center;
		}
	</style>
</head>

<body>
	<div>
		<p>
			生鲜称码：
			<input type="text" id="itemNum" oninput="createcode()">
			</p>
			<p>
			输入价格：
			<input type="text" id="warePriceDesc" oninput="createcode()">
			</p>
			<p>
			商品重量：
			<input type="text" id="wareWeightDesc" oninput="createcode()">
			</p>
			<svg id="barcode23"/>
            <br/>
            请注意！上面的条码是小百专用的，
            非小百的商品不要用！千万不要用！
			<svg id="barcode25"/>
            <svg id="barcode26"/>
		</div>
		<script>
            var $ = function (x) {
                return document.getElementById(x);
            };
            function createcode() {
                var wareTypeDesc = ['23', '25', '26'];
                var itemNum = $('itemNum').value;
                var warePriceDesc = ($('warePriceDesc').value * 100 + 0.1) >>> 0;
                var wareWeightDesc = $('wareWeightDesc').value;
                var i, j, t;
                t = '';
                for (i = 0; i < 5 - itemNum.length; i++) {
                    t += '0';
                }
                itemNum = t + itemNum;
                t = '';
                warePriceDesc += '';
                for (i = 0; i < 5 - warePriceDesc.length; i++) {
                    t += '0';
                }
                warePriceDesc = t + warePriceDesc;
                t = '';
                for (i = 0; i < 5 - wareWeightDesc.length; i++) {
                    t += '0';
                }
                wareWeightDesc = t + wareWeightDesc;
                var newcode = [
                    '23' + itemNum + warePriceDesc + wareWeightDesc,
                    '25' + itemNum + warePriceDesc + '00001',
                    '26' + itemNum + warePriceDesc + wareWeightDesc
                ];
                for (i = 0; i < 3; i++) {
                    if (newcode[i].length == 17) {
                        var parityb = 0;
                        for (j = 0; j < 17; j++) {
                            if (j % 2 == 0) {
                                parityb += newcode[i][j] * 3;
                            } else {
                                parityb += newcode[i][j] * 1;
                            }
                        }
                        parityb = parityb * 9 % 10;
                        newcode[i] += parityb;
                        JsBarcode("#barcode" + wareTypeDesc[i], newcode[i], {
                            format: "code128",
                            width: 1.6,
                            height: 48,
                            displayValue: true,
                            fontSize: 16
                        });
                    }
                }
            }
            createcode();
		</script>
	</body>
</html>